﻿using commonFramwork.Log;
using Myu.Interface.InterFace;
using Myu.Redis.Init;
using ServiceStack.Redis;
using System;
using System.Collections.Generic;
using System.Text;

namespace Myu.BLL.RedisHelper
{
    public class RedisHelper
    {
        private static IRedisClient client = RedisManager.GetClient();
        private static MyuLogger loger = new MyuLogger(typeof(RedisHelper));

        public static T GetCache<T>(string key)
        {
            using (IRedisClient client = RedisManager.GetClient())
            {
                var entity = client.Get<T>(key);
                return entity;
            }
        }


        public static bool SaveCache<T>(string key , T source)
        {
            using (IRedisClient client = RedisManager.GetClient())
            {
                try
                {
                    client.Set<T>(key, source);
                    return true;
                }
                catch (Exception ex)
                {
                    loger.Error(ex.Message);
                    return false;
                }
                
            }
        }
    }
}
